﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Cuckoo.TaskSchedule
{
	/// <summary>
	/// 任务调度主程序
	/// </summary>
	public class TaskDispatch
	{
		private TaskDispatch() { }

		private static TaskDispatch _Instance;
		public static TaskDispatch Instance
		{
			get
			{
				if (_Instance == null)
				{
					_Instance = new TaskDispatch();
				}
				return _Instance;
			}
		}

		/// <summary>
		/// 注册任务
		/// </summary>
		/// <param name="task">待注册任务</param>
		public static void RegisterTask(ITask task)
		{
			//根据任务类型获取响应的任务策略类对象
			ITaskStrategy strategy = TaskStrategyFactory.CreateTaskStrategy(task);
			strategy.RegisterTask(task);
		}

		/// <summary>
		/// 注销任务
		/// </summary>
		/// <param name="task">待注销任务</param>
		public void UnRegisterTask(ITask task)
		{
			//根据任务类型获取响应的任务策略类对象
			ITaskStrategy strategy = TaskStrategyFactory.CreateTaskStrategy(task);
			strategy.UnRegisterTask(task);
		}
	}
}
